package logic

import (
	"context"
	"gorm.io/gorm"
	"house_srv/models/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseUpdateLogic {
	return &HouseUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseUpdateLogic) HouseUpdate(in *house.HouseUpdateRequest) (*house.HouseUpdateResponse, error) {
	// todo: add your logic here and delete this line
	h := mysql.House{}
	mysql.Db.Where("id = ? ", in.HouseId).Find(&h)
	m := mysql.House{
		Model:       gorm.Model{ID: uint(in.HouseId)},
		UserId:      in.UserId,
		HouseName:   in.HouseName,
		HousePrice:  in.HousePrice,
		Floor:       in.Floor,
		Acreage:     in.Acreage,
		Address:     in.Address,
		HouseType:   in.HouseType,
		HouseStatus: in.HouseStatus,
	}
	mysql.Db.Debug().Updates(&m)
	return &house.HouseUpdateResponse{
		HouseId: int64(h.ID),
	}, nil
}
